Skip to content

Commit f020e8d

Browse files
Merge branch 'release_70' of https://github.com/llvm-mirror/clang into release_70
2 parents 71a5a84 + 65f8432 commit f020e8d

File tree

17 files changed

+224
-41
lines changed

17 files changed

+224
-41
lines changed

bindings/python/tests/cindex/test_code_completion.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class Q : public P {
6161
cr = tu.codeComplete('fake.cpp', 12, 5, unsaved_files=files)
6262

6363
expected = [
64-
"{'const', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
65-
"{'volatile', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
64+
"{'const', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
65+
"{'volatile', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
6666
"{'operator', TypedText} || Priority: 40 || Availability: Available || Brief comment: None",
67-
"{'P', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None",
68-
"{'Q', TypedText} | {'::', Text} || Priority: 75 || Availability: Available || Brief comment: None"
67+
"{'P', TypedText} || Priority: 50 || Availability: Available || Brief comment: None",
68+
"{'Q', TypedText} || Priority: 50 || Availability: Available || Brief comment: None"
6969
]
7070
self.check_completion_results(cr, expected)
7171

include/clang/AST/Decl.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,23 +2269,30 @@ class FunctionDecl : public DeclaratorDecl, public DeclContext,
22692269
unsigned getMinRequiredArguments() const;
22702270

22712271
QualType getReturnType() const {
2272-
assert(getType()->getAs<FunctionType>() && "Expected a FunctionType!");
2273-
return getType()->getAs<FunctionType>()->getReturnType();
2272+
return getType()->castAs<FunctionType>()->getReturnType();
22742273
}
22752274

22762275
/// Attempt to compute an informative source range covering the
22772276
/// function return type. This may omit qualifiers and other information with
22782277
/// limited representation in the AST.
22792278
SourceRange getReturnTypeSourceRange() const;
22802279

2280+
/// Get the declared return type, which may differ from the actual return
2281+
/// type if the return type is deduced.
2282+
QualType getDeclaredReturnType() const {
2283+
auto *TSI = getTypeSourceInfo();
2284+
QualType T = TSI ? TSI->getType() : getType();
2285+
return T->castAs<FunctionType>()->getReturnType();
2286+
}
2287+
22812288
/// Attempt to compute an informative source range covering the
22822289
/// function exception specification, if any.
22832290
SourceRange getExceptionSpecSourceRange() const;
22842291

22852292
/// Determine the type of an expression that calls this function.
22862293
QualType getCallResultType() const {
2287-
assert(getType()->getAs<FunctionType>() && "Expected a FunctionType!");
2288-
return getType()->getAs<FunctionType>()->getCallResultType(getASTContext());
2294+
return getType()->castAs<FunctionType>()->getCallResultType(
2295+
getASTContext());
22892296
}
22902297

22912298
/// Returns the WarnUnusedResultAttr that is either declared on this

include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def fconstexpr_backtrace_limit_EQ : Joined<["-"], "fconstexpr-backtrace-limit=">
802802
Group<f_Group>;
803803
def fno_crash_diagnostics : Flag<["-"], "fno-crash-diagnostics">, Group<f_clang_Group>, Flags<[NoArgumentUnused]>,
804804
HelpText<"Disable auto-generation of preprocessed source files and a script for reproduction during a clang crash">;
805-
def fcrash_diagnostics_dir : Joined<["-"], "fcrash-diagnostics-dir=">, Group<f_clang_Group>, Flags<[NoArgumentUnused]>;
805+
def fcrash_diagnostics_dir : Joined<["-"], "fcrash-diagnostics-dir=">, Group<f_clang_Group>, Flags<[NoArgumentUnused, CoreOption]>;
806806
def fcreate_profile : Flag<["-"], "fcreate-profile">, Group<f_Group>;
807807
def fcxx_exceptions: Flag<["-"], "fcxx-exceptions">, Group<f_Group>,
808808
HelpText<"Enable C++ exceptions">, Flags<[CC1Option]>;

include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,8 @@ class Sema {
19501950
FunctionDecl *NewFD, LookupResult &Previous,
19511951
bool IsMemberSpecialization);
19521952
bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl);
1953+
bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
1954+
QualType NewT, QualType OldT);
19531955
void CheckMain(FunctionDecl *FD, const DeclSpec &D);
19541956
void CheckMSVCRTEntryPoint(FunctionDecl *FD);
19551957
Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition);

lib/Driver/Driver.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,9 +3012,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
30123012
Args.eraseArg(options::OPT__SLASH_Yc);
30133013
YcArg = nullptr;
30143014
}
3015-
if (Args.hasArg(options::OPT__SLASH_Y_)) {
3016-
// /Y- disables all pch handling. Rather than check for it everywhere,
3017-
// just remove clang-cl pch-related flags here.
3015+
if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) {
3016+
// If only preprocessing or /Y- is used, all pch handling is disabled.
3017+
// Rather than check for it everywhere, just remove clang-cl pch-related
3018+
// flags here.
30183019
Args.eraseArg(options::OPT__SLASH_Fp);
30193020
Args.eraseArg(options::OPT__SLASH_Yc);
30203021
Args.eraseArg(options::OPT__SLASH_Yu);

lib/Driver/ToolChains/Gnu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
237237
case llvm::Triple::aarch64:
238238
return "aarch64linux";
239239
case llvm::Triple::aarch64_be:
240-
return "aarch64_be_linux";
240+
return "aarch64linuxb";
241241
case llvm::Triple::arm:
242242
case llvm::Triple::thumb:
243243
return "armelf_linux_eabi";

lib/Sema/SemaDecl.cpp

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3249,20 +3249,15 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
32493249
// Redeclarations or specializations of a function or function template
32503250
// with a declared return type that uses a placeholder type shall also
32513251
// use that placeholder, not a deduced type.
3252-
QualType OldDeclaredReturnType =
3253-
(Old->getTypeSourceInfo()
3254-
? Old->getTypeSourceInfo()->getType()->castAs<FunctionType>()
3255-
: OldType)->getReturnType();
3256-
QualType NewDeclaredReturnType =
3257-
(New->getTypeSourceInfo()
3258-
? New->getTypeSourceInfo()->getType()->castAs<FunctionType>()
3259-
: NewType)->getReturnType();
3252+
QualType OldDeclaredReturnType = Old->getDeclaredReturnType();
3253+
QualType NewDeclaredReturnType = New->getDeclaredReturnType();
32603254
if (!Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
3261-
!((NewQType->isDependentType() || OldQType->isDependentType()) &&
3262-
New->isLocalExternDecl())) {
3255+
canFullyTypeCheckRedeclaration(New, Old, NewDeclaredReturnType,
3256+
OldDeclaredReturnType)) {
32633257
QualType ResQT;
32643258
if (NewDeclaredReturnType->isObjCObjectPointerType() &&
32653259
OldDeclaredReturnType->isObjCObjectPointerType())
3260+
// FIXME: This does the wrong thing for a deduced return type.
32663261
ResQT = Context.mergeObjCGCQualifiers(NewQType, OldQType);
32673262
if (ResQT.isNull()) {
32683263
if (New->isCXXClassMember() && New->isOutOfLine())
@@ -3427,13 +3422,11 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
34273422
if (OldQTypeForComparison == NewQType)
34283423
return MergeCompatibleFunctionDecls(New, Old, S, MergeTypeWithOld);
34293424

3430-
if ((NewQType->isDependentType() || OldQType->isDependentType()) &&
3431-
New->isLocalExternDecl()) {
3432-
// It's OK if we couldn't merge types for a local function declaraton
3433-
// if either the old or new type is dependent. We'll merge the types
3434-
// when we instantiate the function.
3425+
// If the types are imprecise (due to dependent constructs in friends or
3426+
// local extern declarations), it's OK if they differ. We'll check again
3427+
// during instantiation.
3428+
if (!canFullyTypeCheckRedeclaration(New, Old, NewQType, OldQType))
34353429
return false;
3436-
}
34373430

34383431
// Fall through for conflicting redeclarations and redefinitions.
34393432
}
@@ -9336,6 +9329,39 @@ Attr *Sema::getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD,
93369329
}
93379330
return nullptr;
93389331
}
9332+
9333+
/// Determines if we can perform a correct type check for \p D as a
9334+
/// redeclaration of \p PrevDecl. If not, we can generally still perform a
9335+
/// best-effort check.
9336+
///
9337+
/// \param NewD The new declaration.
9338+
/// \param OldD The old declaration.
9339+
/// \param NewT The portion of the type of the new declaration to check.
9340+
/// \param OldT The portion of the type of the old declaration to check.
9341+
bool Sema::canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
9342+
QualType NewT, QualType OldT) {
9343+
if (!NewD->getLexicalDeclContext()->isDependentContext())
9344+
return true;
9345+
9346+
// For dependently-typed local extern declarations and friends, we can't
9347+
// perform a correct type check in general until instantiation:
9348+
//
9349+
// int f();
9350+
// template<typename T> void g() { T f(); }
9351+
//
9352+
// (valid if g() is only instantiated with T = int).
9353+
if (NewT->isDependentType() &&
9354+
(NewD->isLocalExternDecl() || NewD->getFriendObjectKind()))
9355+
return false;
9356+
9357+
// Similarly, if the previous declaration was a dependent local extern
9358+
// declaration, we don't really know its type yet.
9359+
if (OldT->isDependentType() && OldD->isLocalExternDecl())
9360+
return false;
9361+
9362+
return true;
9363+
}
9364+
93399365
/// Checks if the new declaration declared in dependent context must be
93409366
/// put in the same redeclaration chain as the specified declaration.
93419367
///
@@ -9346,20 +9372,30 @@ Attr *Sema::getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD,
93469372
/// belongs to.
93479373
///
93489374
bool Sema::shouldLinkDependentDeclWithPrevious(Decl *D, Decl *PrevDecl) {
9349-
// Any declarations should be put into redeclaration chains except for
9350-
// friend declaration in a dependent context that names a function in
9351-
// namespace scope.
9375+
if (!D->getLexicalDeclContext()->isDependentContext())
9376+
return true;
9377+
9378+
// Don't chain dependent friend function definitions until instantiation, to
9379+
// permit cases like
93529380
//
9353-
// This allows to compile code like:
9381+
// void func();
9382+
// template<typename T> class C1 { friend void func() {} };
9383+
// template<typename T> class C2 { friend void func() {} };
93549384
//
9355-
// void func();
9356-
// template<typename T> class C1 { friend void func() { } };
9357-
// template<typename T> class C2 { friend void func() { } };
9385+
// ... which is valid if only one of C1 and C2 is ever instantiated.
93589386
//
9359-
// This code snippet is a valid code unless both templates are instantiated.
9360-
return !(D->getLexicalDeclContext()->isDependentContext() &&
9361-
D->getDeclContext()->isFileContext() &&
9362-
D->getFriendObjectKind() != Decl::FOK_None);
9387+
// FIXME: This need only apply to function definitions. For now, we proxy
9388+
// this by checking for a file-scope function. We do not want this to apply
9389+
// to friend declarations nominating member functions, because that gets in
9390+
// the way of access checks.
9391+
if (D->getFriendObjectKind() && D->getDeclContext()->isFileContext())
9392+
return false;
9393+
9394+
auto *VD = dyn_cast<ValueDecl>(D);
9395+
auto *PrevVD = dyn_cast<ValueDecl>(PrevDecl);
9396+
return !VD || !PrevVD ||
9397+
canFullyTypeCheckRedeclaration(VD, PrevVD, VD->getType(),
9398+
PrevVD->getType());
93639399
}
93649400

93659401
namespace MultiVersioning {

lib/Sema/SemaOverload.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ bool Sema::IsOverload(FunctionDecl *New, FunctionDecl *Old,
11051105
(!TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(),
11061106
OldTemplate->getTemplateParameters(),
11071107
false, TPL_TemplateMatch) ||
1108-
OldType->getReturnType() != NewType->getReturnType()))
1108+
!Context.hasSameType(Old->getDeclaredReturnType(),
1109+
New->getDeclaredReturnType())))
11091110
return true;
11101111

11111112
// If the function is a class member, its signature includes the

lib/Sema/SemaTemplate.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8304,6 +8304,8 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
83048304
QualType Adjusted = Function->getType();
83058305
if (!hasExplicitCallingConv(Adjusted))
83068306
Adjusted = adjustCCAndNoReturn(Adjusted, Method->getType());
8307+
// This doesn't handle deduced return types, but both function
8308+
// declarations should be undeduced at this point.
83078309
if (Context.hasSameType(Adjusted, Method->getType())) {
83088310
FoundInstantiation = *I;
83098311
Instantiation = Method;

test/Driver/cl-options.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@
566566
// RUN: %clang_cl \
567567
// RUN: --driver-mode=cl \
568568
// RUN: -fblocks \
569+
// RUN: -fcrash-diagnostics-dir=/foo \
569570
// RUN: -fno-blocks \
570571
// RUN: -fbuiltin \
571572
// RUN: -fno-builtin \

0 commit comments

Comments
 (0)