Skip to content

Commit ca4c1ee

Browse files
committed
Merge remote-tracking branch 'upstream/release/13.x' into rustc/13.0-2021-08-08
2 parents 609f806 + aac4fe3 commit ca4c1ee

File tree

79 files changed

+3301
-751
lines changed

Some content is hidden

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

79 files changed

+3301
-751
lines changed

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
7878
return;
7979

8080
QualType TypePtr = MatchedDecl->getType();
81-
const char *InitializationString = nullptr;
81+
llvm::Optional<const char *> InitializationString = llvm::None;
8282
bool AddMathInclude = false;
8383

84-
if (TypePtr->isIntegerType())
84+
if (TypePtr->isEnumeralType())
85+
InitializationString = nullptr;
86+
else if (TypePtr->isIntegerType())
8587
InitializationString = " = 0";
8688
else if (TypePtr->isFloatingType()) {
8789
InitializationString = " = NAN";
@@ -96,11 +98,12 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
9698
if (InitializationString) {
9799
auto Diagnostic =
98100
diag(MatchedDecl->getLocation(), "variable %0 is not initialized")
99-
<< MatchedDecl
100-
<< FixItHint::CreateInsertion(
101-
MatchedDecl->getLocation().getLocWithOffset(
102-
MatchedDecl->getName().size()),
103-
InitializationString);
101+
<< MatchedDecl;
102+
if (*InitializationString != nullptr)
103+
Diagnostic << FixItHint::CreateInsertion(
104+
MatchedDecl->getLocation().getLocWithOffset(
105+
MatchedDecl->getName().size()),
106+
*InitializationString);
104107
if (AddMathInclude) {
105108
Diagnostic << IncludeInserter.createIncludeInsertion(
106109
Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader);

clang-tools-extra/docs/ReleaseNotes.rst

+9
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,22 @@ Changes in existing checks
151151

152152
Added an option to choose the set of allowed functions.
153153

154+
- Improved :doc:`cppcoreguidelines-init-variables
155+
<clang-tidy/checks/cppcoreguidelines-init-variables>` check.
156+
157+
Removed generating fixes for enums because the code generated was broken,
158+
trying to initialize the enum from an integer.
159+
160+
The check now also warns for uninitialized scoped enums.
161+
154162
- Improved :doc:`readability-uniqueptr-delete-release
155163
<clang-tidy/checks/readability-uniqueptr-delete-release>` check.
156164

157165
Added an option to choose whether to refactor by calling the ``reset`` member
158166
function or assignment to ``nullptr``.
159167
Added support for pointers to ``std::unique_ptr``.
160168

169+
161170
Removed checks
162171
^^^^^^^^^^^^^^
163172

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-init-variables.rst

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ Would be rewritten to look like this:
3737
// Rest of the function.
3838
}
3939

40+
It warns for the uninitialized enum case, but without a FixIt:
41+
42+
.. code-block:: c++
43+
44+
enum A {A1, A2, A3};
45+
enum A_c : char { A_c1, A_c2, A_c3 };
46+
enum class B { B1, B2, B3 };
47+
enum class B_i : int { B_i1, B_i2, B_i3 };
48+
void function() {
49+
A a; // Warning: variable 'a' is not initialized
50+
A_c a_c; // Warning: variable 'a_c' is not initialized
51+
B b; // Warning: variable 'b' is not initialized
52+
B_i b_i; // Warning: variable 'b_i' is not initialized
53+
}
54+
4055
Options
4156
-------
4257

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

+32
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,35 @@ void catch_variable_decl() {
9292
} catch (int X) {
9393
}
9494
}
95+
96+
enum Color { Red,
97+
Green,
98+
Blue };
99+
100+
enum Car { Benz,
101+
BMW = 20,
102+
Audi = BMW + 2 };
103+
104+
enum Gender : char { Male,
105+
Female };
106+
107+
enum class Direction { Up,
108+
Down,
109+
Left,
110+
Right };
111+
112+
enum class Fruit : int { Apple,
113+
Orange };
114+
115+
void uninitialized_enum() {
116+
Color color;
117+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'color' is not initialized [cppcoreguidelines-init-variables]
118+
Car car;
119+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: variable 'car' is not initialized [cppcoreguidelines-init-variables]
120+
Gender gender;
121+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: variable 'gender' is not initialized [cppcoreguidelines-init-variables]
122+
Direction direction;
123+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'direction' is not initialized [cppcoreguidelines-init-variables]
124+
Fruit fruit;
125+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: variable 'fruit' is not initialized [cppcoreguidelines-init-variables]
126+
}

clang/include/clang/Sema/Sema.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -7828,8 +7828,7 @@ class Sema final {
78287828
TemplateArgumentLoc &Arg,
78297829
SmallVectorImpl<TemplateArgument> &Converted);
78307830

7831-
bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
7832-
TypeSourceInfo *Arg);
7831+
bool CheckTemplateArgument(TypeSourceInfo *Arg);
78337832
ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
78347833
QualType InstantiatedParamType, Expr *Arg,
78357834
TemplateArgument &Converted,

clang/lib/AST/ASTContext.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -6066,9 +6066,11 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
60666066
NNS->getAsNamespaceAlias()->getNamespace()
60676067
->getOriginalNamespace());
60686068

6069+
// The difference between TypeSpec and TypeSpecWithTemplate is that the
6070+
// latter will have the 'template' keyword when printed.
60696071
case NestedNameSpecifier::TypeSpec:
60706072
case NestedNameSpecifier::TypeSpecWithTemplate: {
6071-
QualType T = getCanonicalType(QualType(NNS->getAsType(), 0));
6073+
const Type *T = getCanonicalType(NNS->getAsType());
60726074

60736075
// If we have some kind of dependent-named type (e.g., "typename T::type"),
60746076
// break it apart into its prefix and identifier, then reconsititute those
@@ -6078,14 +6080,16 @@ ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
60786080
// typedef typename T::type T1;
60796081
// typedef typename T1::type T2;
60806082
if (const auto *DNT = T->getAs<DependentNameType>())
6081-
return NestedNameSpecifier::Create(*this, DNT->getQualifier(),
6082-
const_cast<IdentifierInfo *>(DNT->getIdentifier()));
6083-
6084-
// Otherwise, just canonicalize the type, and force it to be a TypeSpec.
6085-
// FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the
6086-
// first place?
6083+
return NestedNameSpecifier::Create(
6084+
*this, DNT->getQualifier(),
6085+
const_cast<IdentifierInfo *>(DNT->getIdentifier()));
6086+
if (const auto *DTST = T->getAs<DependentTemplateSpecializationType>())
6087+
return NestedNameSpecifier::Create(*this, DTST->getQualifier(), true,
6088+
const_cast<Type *>(T));
6089+
6090+
// TODO: Set 'Template' parameter to true for other template types.
60876091
return NestedNameSpecifier::Create(*this, nullptr, false,
6088-
const_cast<Type *>(T.getTypePtr()));
6092+
const_cast<Type *>(T));
60896093
}
60906094

60916095
case NestedNameSpecifier::Global:

clang/lib/Driver/ToolChains/MinGW.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
136136
llvm_unreachable("Unsupported target architecture.");
137137
}
138138

139-
if (Args.hasArg(options::OPT_mwindows)) {
139+
Arg *SubsysArg =
140+
Args.getLastArg(options::OPT_mwindows, options::OPT_mconsole);
141+
if (SubsysArg && SubsysArg->getOption().matches(options::OPT_mwindows)) {
140142
CmdArgs.push_back("--subsystem");
141143
CmdArgs.push_back("windows");
142-
} else if (Args.hasArg(options::OPT_mconsole)) {
144+
} else if (SubsysArg &&
145+
SubsysArg->getOption().matches(options::OPT_mconsole)) {
143146
CmdArgs.push_back("--subsystem");
144147
CmdArgs.push_back("console");
145148
}

clang/lib/Sema/SemaDeclCXX.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -12472,6 +12472,8 @@ bool Sema::CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
1247212472
return false;
1247312473
}
1247412474

12475+
const NestedNameSpecifier *CNNS =
12476+
Context.getCanonicalNestedNameSpecifier(Qual);
1247512477
for (LookupResult::iterator I = Prev.begin(), E = Prev.end(); I != E; ++I) {
1247612478
NamedDecl *D = *I;
1247712479

@@ -12497,8 +12499,7 @@ bool Sema::CheckUsingDeclRedeclaration(SourceLocation UsingLoc,
1249712499
// using decls differ if they name different scopes (but note that
1249812500
// template instantiation can cause this check to trigger when it
1249912501
// didn't before instantiation).
12500-
if (Context.getCanonicalNestedNameSpecifier(Qual) !=
12501-
Context.getCanonicalNestedNameSpecifier(DQual))
12502+
if (CNNS != Context.getCanonicalNestedNameSpecifier(DQual))
1250212503
continue;
1250312504

1250412505
Diag(NameLoc, diag::err_using_decl_redeclaration) << SS.getRange();

clang/lib/Sema/SemaTemplate.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ NamedDecl *Sema::ActOnTypeParameter(Scope *S, bool Typename,
10791079
return Param;
10801080

10811081
// Check the template argument itself.
1082-
if (CheckTemplateArgument(Param, DefaultTInfo)) {
1082+
if (CheckTemplateArgument(DefaultTInfo)) {
10831083
Param->setInvalidDecl();
10841084
return Param;
10851085
}
@@ -5042,7 +5042,7 @@ bool Sema::CheckTemplateTypeArgument(TemplateTypeParmDecl *Param,
50425042
}
50435043
}
50445044

5045-
if (CheckTemplateArgument(Param, TSI))
5045+
if (CheckTemplateArgument(TSI))
50465046
return true;
50475047

50485048
// Add the converted template type argument.
@@ -5661,7 +5661,7 @@ bool Sema::CheckTemplateArgumentList(
56615661
TemplateArgumentListInfo NewArgs = TemplateArgs;
56625662

56635663
// Make sure we get the template parameter list from the most
5664-
// recentdeclaration, since that is the only one that has is guaranteed to
5664+
// recent declaration, since that is the only one that is guaranteed to
56655665
// have all the default template argument information.
56665666
TemplateParameterList *Params =
56675667
cast<TemplateDecl>(Template->getMostRecentDecl())
@@ -6208,8 +6208,7 @@ bool UnnamedLocalNoLinkageFinder::VisitNestedNameSpecifier(
62086208
///
62096209
/// This routine implements the semantics of C++ [temp.arg.type]. It
62106210
/// returns true if an error occurred, and false otherwise.
6211-
bool Sema::CheckTemplateArgument(TemplateTypeParmDecl *Param,
6212-
TypeSourceInfo *ArgInfo) {
6211+
bool Sema::CheckTemplateArgument(TypeSourceInfo *ArgInfo) {
62136212
assert(ArgInfo && "invalid TypeSourceInfo");
62146213
QualType Arg = ArgInfo->getType();
62156214
SourceRange SR = ArgInfo->getTypeLoc().getSourceRange();

clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,23 @@ template <True T, Bar2 U>
8181
requires true struct S4; // expected-note {{template is declared here}}
8282
template <True T, True U>
8383
requires true struct S4<T, U>; // expected-error {{class template partial specialization is not more specialized than the primary template}}
84+
85+
struct X {
86+
template<int> struct Y {
87+
using type = int;
88+
};
89+
};
90+
91+
template<class T> concept C1 = sizeof(T) != 0;
92+
template<class T> concept C2 = C1<typename T::template Y<1>::type>;
93+
94+
template<class T> requires C1<T> void t1() = delete; // expected-note {{candidate function}}
95+
template<class T> requires C1<T> && C2<T> void t1() = delete; // expected-note {{candidate function}}
96+
template void t1<X>();
97+
void t1() { t1<X>(); } // expected-error {{call to deleted function 't1'}}
98+
99+
template<class T> requires C1<T> void t2() {}; // expected-note 2 {{candidate function}}
100+
template<class T> requires C2<T> void t2() {}; // expected-note 2 {{candidate function}}
101+
template void t2<X>(); // expected-error {{partial ordering for explicit instantiation of 't2' is ambiguous}}
102+
void t2() { t2<X>(); } // expected-error {{call to 't2' is ambiguous}}
84103
} // namespace PR47174

clang/test/Driver/mingw.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@
6161
// RUN: %clang -target i686-windows-gnu -E -### %s -municode 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UNICODE %s
6262
// CHECK_MINGW_NO_UNICODE-NOT: "-DUNICODE"
6363
// CHECK_MINGW_UNICODE: "-DUNICODE"
64+
65+
// RUN: %clang -target i686-windows-gnu -### %s 2>&1 | FileCheck -check-prefix=CHECK_NO_SUBSYS %s
66+
// RUN: %clang -target i686-windows-gnu -### %s -mwindows -mconsole 2>&1 | FileCheck -check-prefix=CHECK_SUBSYS_CONSOLE %s
67+
// RUN: %clang -target i686-windows-gnu -### %s -mconsole -mwindows 2>&1 | FileCheck -check-prefix=CHECK_SUBSYS_WINDOWS %s
68+
// CHECK_NO_SUBSYS-NOT: "--subsystem"
69+
// CHECK_SUBSYS_CONSOLE: "--subsystem" "console"
70+
// CHECK_SUBSYS_WINDOWS: "--subsystem" "windows"

clang/tools/libclang/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ if(ENABLE_SHARED)
162162
endif()
163163
if (USE_VERSION_SCRIPT)
164164
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
165+
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
166+
# but requires a special option to enable it.
167+
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
168+
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
169+
endif()
165170
# Ensure that libclang.so gets rebuilt when the linker script changes.
166171
set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
167172
OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)

clang/tools/libclang/libclang.map

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
/* If you add a symbol to this file, make sure to add it with the correct
2-
* version. For example, if the LLVM main branch is LLVM 14.0.0, add new
3-
* symbols with the version LLVM_14.
4-
* On platforms where versions scripts are not used, this file will be used to
5-
* generate a list of exports for libclang.so
6-
*/
7-
1+
# If you add a symbol to this file, make sure to add it with the correct
2+
# version. For example, if the LLVM main branch is LLVM 14.0.0, add new
3+
# symbols with the version LLVM_14.
4+
# On platforms where versions scripts are not used, this file will be used to
5+
# generate a list of exports for libclang.so
86

97
LLVM_13 {
108
global:
@@ -49,6 +47,7 @@ LLVM_13 {
4947
clang_CompileCommand_getMappedSourceContent;
5048
clang_CompileCommand_getMappedSourcePath;
5149
clang_CompileCommand_getNumArgs;
50+
clang_CompileCommand_getNumMappedSources;
5251
clang_CompileCommands_dispose;
5352
clang_CompileCommands_getCommand;
5453
clang_CompileCommands_getSize;
@@ -406,10 +405,9 @@ LLVM_13 {
406405
local: *;
407406
};
408407

409-
/* Example of how to add a new symbol version entry. If you do add a new symbol
410-
* version, please update the example to depend on the version you added.
411-
* LLVM_X {
412-
* global:
413-
* clang_newsymbol;
414-
* };
415-
*/
408+
# Example of how to add a new symbol version entry. If you do add a new symbol
409+
# version, please update the example to depend on the version you added.
410+
# LLVM_X {
411+
# global:
412+
# clang_newsymbol;
413+
# };

compiler-rt/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,14 @@ set(COMPILER_RT_GTEST_CFLAGS
537537
-I${COMPILER_RT_GTEST_PATH}/include
538538
-I${COMPILER_RT_GTEST_PATH}
539539
)
540+
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
541+
# FreeBSD has its pthread functions marked with thread safety annotations, but
542+
# googletest is not compatible with such annotations. Disable the thread
543+
# safety warnings-as-errors until googletest has been fixed.
544+
list(APPEND NO_THREAD_SAFETY_FLAGS ${THREAD_SAFETY_FLAGS})
545+
list(TRANSFORM NO_THREAD_SAFETY_FLAGS REPLACE "error=" "no-")
546+
list(APPEND COMPILER_RT_GTEST_CFLAGS ${NO_THREAD_SAFETY_FLAGS})
547+
endif()
540548

541549
# Mocking support.
542550
set(COMPILER_RT_GMOCK_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock)

compiler-rt/include/profile/InstrProfData.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::Type::getInt8PtrTy(Ctx), Next, \
129129
#endif
130130
INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
131131
INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
132+
INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
132133
INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize)
133134
INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, PaddingBytesBeforeCounters)
134135
INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize)
@@ -137,7 +138,6 @@ INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize)
137138
INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
138139
INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
139140
INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
140-
INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
141141
#undef INSTR_PROF_RAW_HEADER
142142
/* INSTR_PROF_RAW_HEADER end */
143143

@@ -646,7 +646,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
646646
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
647647

648648
/* Raw profile format version (start from 1). */
649-
#define INSTR_PROF_RAW_VERSION 6
649+
#define INSTR_PROF_RAW_VERSION 7
650650
/* Indexed profile format version (start from 1). */
651651
#define INSTR_PROF_INDEX_VERSION 7
652652
/* Coverage mapping format version (start from 0). */

compiler-rt/lib/profile/InstrProfilingBuffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ uint64_t __llvm_profile_get_size_for_buffer_internal(
116116
DataSize, CountersSize, NamesSize, &PaddingBytesBeforeCounters,
117117
&PaddingBytesAfterCounters, &PaddingBytesAfterNames);
118118

119-
return sizeof(__llvm_profile_header) +
119+
return sizeof(__llvm_profile_header) + __llvm_write_binary_ids(NULL) +
120120
(DataSize * sizeof(__llvm_profile_data)) + PaddingBytesBeforeCounters +
121121
(CountersSize * sizeof(uint64_t)) + PaddingBytesAfterCounters +
122122
NamesSize + PaddingBytesAfterNames;

0 commit comments

Comments
 (0)