Skip to content

Commit 45e825c

Browse files
committed
Merge remote-tracking branch 'upstream/release/10.x' into rustc/10.0-2020-02-05
2 parents 8831227 + f23caec commit 45e825c

File tree

66 files changed

+908
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+908
-470
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
2929
MathHeader(Options.get("MathHeader", "math.h")) {}
3030

3131
void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
32-
Finder->addMatcher(varDecl(unless(hasInitializer(anything())),
33-
unless(isInstantiated()), isLocalVarDecl(),
34-
unless(isStaticLocal()), isDefinition())
35-
.bind("vardecl"),
36-
this);
32+
std::string BadDecl = "badDecl";
33+
Finder->addMatcher(
34+
varDecl(unless(hasInitializer(anything())), unless(isInstantiated()),
35+
isLocalVarDecl(), unless(isStaticLocal()), isDefinition(),
36+
optionally(hasParent(declStmt(hasParent(
37+
cxxForRangeStmt(hasLoopVariable(varDecl().bind(BadDecl))))))),
38+
unless(equalsBoundNode(BadDecl)))
39+
.bind("vardecl"),
40+
this);
3741
}
3842

3943
void InitVariablesCheck::registerPPCallbacks(const SourceManager &SM,

clang-tools-extra/clangd/Hover.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,13 @@ bool isLiteral(const Expr *E) {
447447

448448
llvm::StringLiteral getNameForExpr(const Expr *E) {
449449
// FIXME: Come up with names for `special` expressions.
450-
return "expression";
450+
//
451+
// It's an known issue for GCC5, https://godbolt.org/z/Z_tbgi. Work around
452+
// that by using explicit conversion constructor.
453+
//
454+
// TODO: Once GCC5 is fully retired and not the minimal requirement as stated
455+
// in `GettingStarted`, please remove the explicit conversion constructor.
456+
return llvm::StringLiteral("expression");
451457
}
452458

453459
// Generates hover info for evaluatable expressions.

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-init-variables.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ void init_unit_tests() {
7878
int parens(42);
7979
int braces{42};
8080
}
81+
82+
template <typename RANGE>
83+
void f(RANGE r) {
84+
for (char c : r) {
85+
}
86+
}

clang/docs/ReleaseNotes.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,24 @@ libclang
427427
Static Analyzer
428428
---------------
429429

430-
- The Clang analyzer checker ``DeadStores`` gets a new option called
431-
``WarnForDeadNestedAssignments`` to detect nested dead assignments
432-
(enabled by default).
433-
- ...
430+
- New checker: ``alpha.cplusplus.PlacementNew`` to detect whether the storage
431+
provided for default placement new is sufficiently large.
432+
433+
- New checker: ``fuchsia.HandleChecker`` to detect leaks related to Fuchsia
434+
handles.
435+
436+
- New checker: ``security.insecureAPI.decodeValueOfObjCType`` warns about
437+
potential buffer overflows when using ``[NSCoder decodeValueOfObjCType:at:]``
438+
439+
- ``deadcode.DeadStores`` now warns about nested dead stores.
440+
441+
- Condition values that are relevant to the occurance of a bug are far better
442+
explained in bug reports.
443+
444+
- Despite still being at an alpha stage, checkers implementing taint analyses
445+
and C++ iterator rules were improved greatly.
446+
447+
- Numerous smaller fixes.
434448

435449
.. _release-notes-ubsan:
436450

clang/include/clang/Driver/CC1Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">
859859
HelpText<"include a detailed record of preprocessing actions">;
860860
def setup_static_analyzer : Flag<["-"], "setup-static-analyzer">,
861861
HelpText<"Set up preprocessor for static analyzer (done automatically when static analyzer is run).">;
862+
def disable_pragma_debug_crash : Flag<["-"], "disable-pragma-debug-crash">,
863+
HelpText<"Disable any #pragma clang __debug that can lead to crashing behavior. This is meant for testing.">;
862864

863865
//===----------------------------------------------------------------------===//
864866
// OpenCL Options

clang/include/clang/Lex/PreprocessorOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ class PreprocessorOptions {
189189
/// Set up preprocessor for RunAnalysis action.
190190
bool SetUpStaticAnalyzer = false;
191191

192+
/// Prevents intended crashes when using #pragma clang __debug. For testing.
193+
bool DisablePragmaDebugCrash = false;
194+
192195
public:
193196
PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
194197

clang/lib/Driver/Compilation.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,23 @@ void Compilation::initCompilationForDiagnostics() {
258258

259259
// Remove any user specified output. Claim any unclaimed arguments, so as
260260
// to avoid emitting warnings about unused args.
261-
OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
262-
options::OPT_MMD };
261+
OptSpecifier OutputOpts[] = {
262+
options::OPT_o, options::OPT_MD, options::OPT_MMD, options::OPT_M,
263+
options::OPT_MM, options::OPT_MF, options::OPT_MG, options::OPT_MJ,
264+
options::OPT_MQ, options::OPT_MT, options::OPT_MV};
263265
for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
264266
if (TranslatedArgs->hasArg(OutputOpts[i]))
265267
TranslatedArgs->eraseArg(OutputOpts[i]);
266268
}
267269
TranslatedArgs->ClaimAllArgs();
268270

271+
// Force re-creation of the toolchain Args, otherwise our modifications just
272+
// above will have no effect.
273+
for (auto Arg : TCArgs)
274+
if (Arg.second != TranslatedArgs)
275+
delete Arg.second;
276+
TCArgs.clear();
277+
269278
// Redirect stdout/stderr to /dev/null.
270279
Redirects = {None, {""}, {""}};
271280

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,6 +4679,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46794679
: "-");
46804680
}
46814681

4682+
// Give the gen diagnostics more chances to succeed, by avoiding intentional
4683+
// crashes.
4684+
if (D.CCGenDiagnostics)
4685+
CmdArgs.push_back("-disable-pragma-debug-crash");
4686+
46824687
bool UseSeparateSections = isUseSeparateSections(Triple);
46834688

46844689
if (Args.hasFlag(options::OPT_ffunction_sections,

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,7 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
34403440
Opts.LexEditorPlaceholders = false;
34413441

34423442
Opts.SetUpStaticAnalyzer = Args.hasArg(OPT_setup_static_analyzer);
3443+
Opts.DisablePragmaDebugCrash = Args.hasArg(OPT_disable_pragma_debug_crash);
34433444
}
34443445

34453446
static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,

clang/lib/Lex/Pragma.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "clang/Lex/PPCallbacks.h"
3131
#include "clang/Lex/Preprocessor.h"
3232
#include "clang/Lex/PreprocessorLexer.h"
33+
#include "clang/Lex/PreprocessorOptions.h"
3334
#include "clang/Lex/Token.h"
3435
#include "clang/Lex/TokenLexer.h"
3536
#include "llvm/ADT/ArrayRef.h"
@@ -39,7 +40,6 @@
3940
#include "llvm/ADT/SmallVector.h"
4041
#include "llvm/ADT/StringSwitch.h"
4142
#include "llvm/ADT/StringRef.h"
42-
#include "llvm/Support/CrashRecoveryContext.h"
4343
#include "llvm/Support/Compiler.h"
4444
#include "llvm/Support/ErrorHandling.h"
4545
#include <algorithm>
@@ -1035,15 +1035,19 @@ struct PragmaDebugHandler : public PragmaHandler {
10351035
IdentifierInfo *II = Tok.getIdentifierInfo();
10361036

10371037
if (II->isStr("assert")) {
1038-
llvm_unreachable("This is an assertion!");
1038+
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
1039+
llvm_unreachable("This is an assertion!");
10391040
} else if (II->isStr("crash")) {
1040-
LLVM_BUILTIN_TRAP;
1041+
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
1042+
LLVM_BUILTIN_TRAP;
10411043
} else if (II->isStr("parser_crash")) {
1042-
Token Crasher;
1043-
Crasher.startToken();
1044-
Crasher.setKind(tok::annot_pragma_parser_crash);
1045-
Crasher.setAnnotationRange(SourceRange(Tok.getLocation()));
1046-
PP.EnterToken(Crasher, /*IsReinject*/false);
1044+
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash) {
1045+
Token Crasher;
1046+
Crasher.startToken();
1047+
Crasher.setKind(tok::annot_pragma_parser_crash);
1048+
Crasher.setAnnotationRange(SourceRange(Tok.getLocation()));
1049+
PP.EnterToken(Crasher, /*IsReinject*/ false);
1050+
}
10471051
} else if (II->isStr("dump")) {
10481052
Token Identifier;
10491053
PP.LexUnexpandedToken(Identifier);
@@ -1075,9 +1079,11 @@ struct PragmaDebugHandler : public PragmaHandler {
10751079
<< II->getName();
10761080
}
10771081
} else if (II->isStr("llvm_fatal_error")) {
1078-
llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
1082+
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
1083+
llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
10791084
} else if (II->isStr("llvm_unreachable")) {
1080-
llvm_unreachable("#pragma clang __debug llvm_unreachable");
1085+
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
1086+
llvm_unreachable("#pragma clang __debug llvm_unreachable");
10811087
} else if (II->isStr("macro")) {
10821088
Token MacroName;
10831089
PP.LexUnexpandedToken(MacroName);
@@ -1104,11 +1110,8 @@ struct PragmaDebugHandler : public PragmaHandler {
11041110
}
11051111
M->dump();
11061112
} else if (II->isStr("overflow_stack")) {
1107-
DebugOverflowStack();
1108-
} else if (II->isStr("handle_crash")) {
1109-
llvm::CrashRecoveryContext *CRC =llvm::CrashRecoveryContext::GetCurrent();
1110-
if (CRC)
1111-
CRC->HandleCrash();
1113+
if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
1114+
DebugOverflowStack();
11121115
} else if (II->isStr("captured")) {
11131116
HandleCaptured(PP);
11141117
} else {

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,12 +2290,12 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
22902290
if (TemplateTypeParmDecl *TTP =
22912291
GetContainedInventedTypeParmVisitor().Visit(OldDI->getType())) {
22922292
if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
2293-
auto *Inst = cast<TemplateTypeParmDecl>(
2293+
auto *Inst = cast_or_null<TemplateTypeParmDecl>(
22942294
FindInstantiatedDecl(TTP->getLocation(), TTP, TemplateArgs));
22952295
// We will first get here when instantiating the abbreviated function
22962296
// template's described function, but we might also get here later.
22972297
// Make sure we do not instantiate the TypeConstraint more than once.
2298-
if (Inst && !Inst->hasTypeConstraint()) {
2298+
if (Inst && !Inst->getTypeConstraint()) {
22992299
// TODO: Concepts: do not instantiate the constraint (delayed constraint
23002300
// substitution)
23012301
const ASTTemplateArgumentListInfo *TemplArgInfo

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,23 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
18371837
return nullptr;
18381838
QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
18391839

1840+
if (TemplateParams && TemplateParams->size()) {
1841+
auto *LastParam =
1842+
dyn_cast<TemplateTypeParmDecl>(TemplateParams->asArray().back());
1843+
if (LastParam && LastParam->isImplicit() &&
1844+
LastParam->hasTypeConstraint()) {
1845+
// In abbreviated templates, the type-constraints of invented template
1846+
// type parameters are instantiated with the function type, invalidating
1847+
// the TemplateParameterList which relied on the template type parameter
1848+
// not having a type constraint. Recreate the TemplateParameterList with
1849+
// the updated parameter list.
1850+
TemplateParams = TemplateParameterList::Create(
1851+
SemaRef.Context, TemplateParams->getTemplateLoc(),
1852+
TemplateParams->getLAngleLoc(), TemplateParams->asArray(),
1853+
TemplateParams->getRAngleLoc(), TemplateParams->getRequiresClause());
1854+
}
1855+
}
1856+
18401857
NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
18411858
if (QualifierLoc) {
18421859
QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,
@@ -2177,6 +2194,23 @@ Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(
21772194
return nullptr;
21782195
QualType T = adjustFunctionTypeForInstantiation(SemaRef.Context, D, TInfo);
21792196

2197+
if (TemplateParams && TemplateParams->size()) {
2198+
auto *LastParam =
2199+
dyn_cast<TemplateTypeParmDecl>(TemplateParams->asArray().back());
2200+
if (LastParam && LastParam->isImplicit() &&
2201+
LastParam->hasTypeConstraint()) {
2202+
// In abbreviated templates, the type-constraints of invented template
2203+
// type parameters are instantiated with the function type, invalidating
2204+
// the TemplateParameterList which relied on the template type parameter
2205+
// not having a type constraint. Recreate the TemplateParameterList with
2206+
// the updated parameter list.
2207+
TemplateParams = TemplateParameterList::Create(
2208+
SemaRef.Context, TemplateParams->getTemplateLoc(),
2209+
TemplateParams->getLAngleLoc(), TemplateParams->asArray(),
2210+
TemplateParams->getRAngleLoc(), TemplateParams->getRequiresClause());
2211+
}
2212+
}
2213+
21802214
NestedNameSpecifierLoc QualifierLoc = D->getQualifierLoc();
21812215
if (QualifierLoc) {
21822216
QualifierLoc = SemaRef.SubstNestedNameSpecifierLoc(QualifierLoc,

clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,17 @@ window.addEventListener("keydown", function (event) {
607607
)<<<";
608608
}
609609

610+
static bool shouldDisplayPopUpRange(const SourceRange &Range) {
611+
return !(Range.getBegin().isMacroID() || Range.getEnd().isMacroID());
612+
}
613+
610614
static void
611615
HandlePopUpPieceStartTag(Rewriter &R,
612616
const std::vector<SourceRange> &PopUpRanges) {
613617
for (const auto &Range : PopUpRanges) {
618+
if (!shouldDisplayPopUpRange(Range))
619+
continue;
620+
614621
html::HighlightRange(R, Range.getBegin(), Range.getEnd(), "",
615622
"<table class='variable_popup'><tbody>",
616623
/*IsTokenRange=*/true);
@@ -626,6 +633,8 @@ static void HandlePopUpPieceEndTag(Rewriter &R,
626633
llvm::raw_svector_ostream Out(Buf);
627634

628635
SourceRange Range(Piece.getLocation().asRange());
636+
if (!shouldDisplayPopUpRange(Range))
637+
return;
629638

630639
// Write out the path indices with a right arrow and the message as a row.
631640
Out << "<tr><td valign='top'><div class='PathIndex PathIndexPopUp'>"
@@ -870,7 +879,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,
870879
<< (num - 1)
871880
<< "\" title=\"Previous event ("
872881
<< (num - 1)
873-
<< ")\">&#x2190;</a></div></td>";
882+
<< ")\">&#x2190;</a></div>";
874883
}
875884

876885
os << "</td><td>";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: rm -fR %t
2+
// RUN: mkdir %t
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
4+
// RUN: -analyzer-output=html -o %t -verify %s
5+
// RUN: cat %t/report-*.html | FileCheck %s
6+
7+
void bar(int);
8+
9+
void foo() {
10+
int a;
11+
bar(a); // expected-warning{{1st function call argument is an uninitialized value}}
12+
}
13+
14+
// CHECK-LABEL: <div id="EndPath" class="msg msgEvent" style="margin-left:3ex">
15+
// CHECK-SAME: <table class="msgT">
16+
// CHECK-SAME: <tr>
17+
// CHECK-SAME: <td valign="top">
18+
// CHECK-SAME: <div class="PathIndex PathIndexEvent">2</div>
19+
// CHECK-SAME: </td>
20+
// CHECK-SAME: <td>
21+
// CHECK-SAME: <div class="PathNav">
22+
// CHECK-SAME: <a href="#Path1" title="Previous event (1)">&#x2190;</a>
23+
// CHECK-SAME: </div>
24+
// CHECK-SAME: </td>
25+
// CHECK-NOT: </td>
26+
// CHECK-SAME: <td>
27+
// CHECK-SAME: 1st function call argument is an uninitialized value
28+
// CHECK-SAME: </td>
29+
// CHECK-SAME: </tr>
30+
// CHECK-SAME: </table>
31+
// CHECK-SAME: </div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: rm -fR %t
2+
// RUN: mkdir %t
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
4+
// RUN: -analyzer-output=html -o %t -verify %s
5+
// RUN: cat %t/report-*.html | FileCheck %s
6+
7+
void bar(int);
8+
9+
#define MACRO if (b)
10+
11+
void foo2() {
12+
int a;
13+
int b = 1;
14+
MACRO
15+
bar(a); // expected-warning{{1st function call argument is an uninitialized value}}
16+
}
17+
18+
// For now we don't emit popups inside macros due to UI limitations.
19+
// Once we do, we should test it thoroughly.
20+
21+
// CHECK-LABEL: <tr class="codeline" data-linenumber="14">
22+
// CHECK-NOT: <span class='variable'>
23+
// CHECK-SAME: <span class='macro'>
24+
// CHECK-SAME: MACRO
25+
// CHECK-SAME: <span class='macro_popup'>
26+
// CHECK-SAME: if (b)
27+
// CHECK-SAME: </span>
28+
// CHECK-SAME: </span>

0 commit comments

Comments
 (0)