Skip to content

Commit ad3c9ae

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents e6cd74f + eb00182 commit ad3c9ae

File tree

64 files changed

+9567
-406
lines changed

Some content is hidden

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

64 files changed

+9567
-406
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ Improvements to Clang's diagnostics
590590

591591
- Fixed a false negative ``-Wunused-private-field`` diagnostic when a defaulted comparison operator is defined out of class (#GH116961).
592592

593+
- Clang now supports using alias templates in deduction guides, aligning with the C++ standard,
594+
which treats alias templates as synonyms for their underlying types (#GH54909).
595+
593596
Improvements to Clang's time-trace
594597
----------------------------------
595598

clang/docs/analyzer/checkers.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,29 @@ Check the size argument passed into C string functions for common erroneous patt
18991899
// warn: potential buffer overflow
19001900
}
19011901
1902+
.. _unix-cstring-NotNullTerminated:
1903+
1904+
unix.cstring.NotNullTerminated (C)
1905+
""""""""""""""""""""""""""""""""""
1906+
Check for arguments which are not null-terminated strings;
1907+
applies to the ``strlen``, ``strcpy``, ``strcat``, ``strcmp`` family of functions.
1908+
1909+
Only very fundamental cases are detected where the passed memory block is
1910+
absolutely different from a null-terminated string. This checker does not
1911+
find if a memory buffer is passed where the terminating zero character
1912+
is missing.
1913+
1914+
.. code-block:: c
1915+
1916+
void test1() {
1917+
int l = strlen((char *)&test1); // warn
1918+
}
1919+
1920+
void test2() {
1921+
label:
1922+
int l = strlen((char *)&&label); // warn
1923+
}
1924+
19021925
.. _unix-cstring-NullArg:
19031926
19041927
unix.cstring.NullArg (C)
@@ -3367,29 +3390,6 @@ Checks for overlap in two buffer arguments. Applies to: ``memcpy, mempcpy, wmem
33673390
memcpy(a + 2, a + 1, 8); // warn
33683391
}
33693392
3370-
.. _alpha-unix-cstring-NotNullTerminated:
3371-
3372-
alpha.unix.cstring.NotNullTerminated (C)
3373-
""""""""""""""""""""""""""""""""""""""""
3374-
Check for arguments which are not null-terminated strings;
3375-
applies to the ``strlen``, ``strcpy``, ``strcat``, ``strcmp`` family of functions.
3376-
3377-
Only very fundamental cases are detected where the passed memory block is
3378-
absolutely different from a null-terminated string. This checker does not
3379-
find if a memory buffer is passed where the terminating zero character
3380-
is missing.
3381-
3382-
.. code-block:: c
3383-
3384-
void test1() {
3385-
int l = strlen((char *)&test); // warn
3386-
}
3387-
3388-
void test2() {
3389-
label:
3390-
int l = strlen((char *)&&label); // warn
3391-
}
3392-
33933393
.. _alpha-unix-cstring-OutOfBounds:
33943394
33953395
alpha.unix.cstring.OutOfBounds (C)

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5413,6 +5413,10 @@ def mlam_bh : Flag<["-"], "mlam-bh">, Group<m_loongarch_Features_Group>,
54135413
HelpText<"Enable amswap[_db].{b/h} and amadd[_db].{b/h}">;
54145414
def mno_lam_bh : Flag<["-"], "mno-lam-bh">, Group<m_loongarch_Features_Group>,
54155415
HelpText<"Disable amswap[_db].{b/h} and amadd[_db].{b/h}">;
5416+
def mlamcas : Flag<["-"], "mlamcas">, Group<m_loongarch_Features_Group>,
5417+
HelpText<"Enable amcas[_db].{b/h/w/d}">;
5418+
def mno_lamcas : Flag<["-"], "mno-lamcas">, Group<m_loongarch_Features_Group>,
5419+
HelpText<"Disable amcas[_db].{b/h/w/d}">;
54165420
def mld_seq_sa : Flag<["-"], "mld-seq-sa">, Group<m_loongarch_Features_Group>,
54175421
HelpText<"Do not generate load-load barrier instructions (dbar 0x700)">;
54185422
def mno_ld_seq_sa : Flag<["-"], "mno-ld-seq-sa">, Group<m_loongarch_Features_Group>,

clang/include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,12 @@ def CStringModeling : Checker<"CStringModeling">,
457457
Documentation<NotDocumented>,
458458
Hidden;
459459

460+
def CStringNotNullTerm : Checker<"NotNullTerminated">,
461+
HelpText<"Check for arguments passed to C string functions which are not "
462+
"null-terminated strings">,
463+
Dependencies<[CStringModeling]>,
464+
Documentation<HasDocumentation>;
465+
460466
def CStringNullArg : Checker<"NullArg">,
461467
HelpText<"Check for null pointers being passed as arguments to C string "
462468
"functions">,
@@ -483,11 +489,6 @@ def CStringBufferOverlap : Checker<"BufferOverlap">,
483489
Dependencies<[CStringModeling]>,
484490
Documentation<HasDocumentation>;
485491

486-
def CStringNotNullTerm : Checker<"NotNullTerminated">,
487-
HelpText<"Check for arguments which are not null-terminating strings">,
488-
Dependencies<[CStringModeling]>,
489-
Documentation<HasDocumentation>;
490-
491492
def CStringUninitializedRead : Checker<"UninitializedRead">,
492493
HelpText<"Checks if the string manipulation function would read uninitialized bytes">,
493494
Dependencies<[CStringModeling]>,

clang/lib/Basic/Targets/LoongArch.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
205205
// TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
206206
// arch feature set will be used to include all sub-features belonging to
207207
// the V1.1 ISA version.
208-
if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLD_SEQ_SA &&
209-
HasFeatureDiv32)
208+
if (HasFeatureFrecipe && HasFeatureLAM_BH && HasFeatureLAMCAS &&
209+
HasFeatureLD_SEQ_SA && HasFeatureDiv32)
210210
Builder.defineMacro("__loongarch_arch",
211211
Twine('"') + "la64v1.1" + Twine('"'));
212212
else
@@ -240,6 +240,9 @@ void LoongArchTargetInfo::getTargetDefines(const LangOptions &Opts,
240240
if (HasFeatureLAM_BH)
241241
Builder.defineMacro("__loongarch_lam_bh", Twine(1));
242242

243+
if (HasFeatureLAMCAS)
244+
Builder.defineMacro("__loongarch_lamcas", Twine(1));
245+
243246
if (HasFeatureLD_SEQ_SA)
244247
Builder.defineMacro("__loongarch_ld_seq_sa", Twine(1));
245248

@@ -324,6 +327,8 @@ bool LoongArchTargetInfo::handleTargetFeatures(
324327
HasFeatureFrecipe = true;
325328
else if (Feature == "+lam-bh")
326329
HasFeatureLAM_BH = true;
330+
else if (Feature == "+lamcas")
331+
HasFeatureLAMCAS = true;
327332
else if (Feature == "+ld-seq-sa")
328333
HasFeatureLD_SEQ_SA = true;
329334
else if (Feature == "+div32")

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
3131
bool HasFeatureLASX;
3232
bool HasFeatureFrecipe;
3333
bool HasFeatureLAM_BH;
34+
bool HasFeatureLAMCAS;
3435
bool HasFeatureLD_SEQ_SA;
3536
bool HasFeatureDiv32;
3637

@@ -43,6 +44,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
4344
HasFeatureLASX = false;
4445
HasFeatureFrecipe = false;
4546
HasFeatureLAM_BH = false;
47+
HasFeatureLAMCAS = false;
4648
HasFeatureLD_SEQ_SA = false;
4749
HasFeatureDiv32 = false;
4850
LongDoubleWidth = 128;

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
275275
Features.push_back("-lam-bh");
276276
}
277277

278+
// Select lamcas feature determined by -m[no-]lamcas.
279+
if (const Arg *A =
280+
Args.getLastArg(options::OPT_mlamcas, options::OPT_mno_lamcas)) {
281+
if (A->getOption().matches(options::OPT_mlamcas))
282+
Features.push_back("+lamcas");
283+
else
284+
Features.push_back("-lamcas");
285+
}
286+
278287
// Select ld-seq-sa feature determined by -m[no-]ld-seq-sa.
279288
if (const Arg *A = Args.getLastArg(options::OPT_mld_seq_sa,
280289
options::OPT_mno_ld_seq_sa)) {

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11451,23 +11451,29 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R,
1145111451
bool MightInstantiateToSpecialization = false;
1145211452
if (auto RetTST =
1145311453
TSI->getTypeLoc().getAsAdjusted<TemplateSpecializationTypeLoc>()) {
11454-
TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
11455-
bool TemplateMatches = Context.hasSameTemplateName(
11456-
SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true);
11457-
11458-
const QualifiedTemplateName *Qualifiers =
11459-
SpecifiedName.getAsQualifiedTemplateName();
11460-
assert(Qualifiers && "expected QualifiedTemplate");
11461-
bool SimplyWritten = !Qualifiers->hasTemplateKeyword() &&
11462-
Qualifiers->getQualifier() == nullptr;
11463-
if (SimplyWritten && TemplateMatches)
11464-
AcceptableReturnType = true;
11465-
else {
11466-
// This could still instantiate to the right type, unless we know it
11467-
// names the wrong class template.
11468-
auto *TD = SpecifiedName.getAsTemplateDecl();
11469-
MightInstantiateToSpecialization = !(TD && isa<ClassTemplateDecl>(TD) &&
11470-
!TemplateMatches);
11454+
const TemplateSpecializationType *TST = RetTST.getTypePtr();
11455+
while (TST && TST->isTypeAlias())
11456+
TST = TST->getAliasedType()->getAs<TemplateSpecializationType>();
11457+
11458+
if (TST) {
11459+
TemplateName SpecifiedName = TST->getTemplateName();
11460+
bool TemplateMatches = Context.hasSameTemplateName(
11461+
SpecifiedName, GuidedTemplate, /*IgnoreDeduced=*/true);
11462+
11463+
const QualifiedTemplateName *Qualifiers =
11464+
SpecifiedName.getAsQualifiedTemplateName();
11465+
assert(Qualifiers && "expected QualifiedTemplate");
11466+
bool SimplyWritten = !Qualifiers->hasTemplateKeyword() &&
11467+
Qualifiers->getQualifier() == nullptr;
11468+
if (SimplyWritten && TemplateMatches)
11469+
AcceptableReturnType = true;
11470+
else {
11471+
// This could still instantiate to the right type, unless we know it
11472+
// names the wrong class template.
11473+
auto *TD = SpecifiedName.getAsTemplateDecl();
11474+
MightInstantiateToSpecialization =
11475+
!(TD && isa<ClassTemplateDecl>(TD) && !TemplateMatches);
11476+
}
1147111477
}
1147211478
} else if (!RetTy.hasQualifiers() && RetTy->isDependentType()) {
1147311479
MightInstantiateToSpecialization = true;

clang/test/Analysis/analyzer-enabled-checkers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
// CHECK-NEXT: unix.StdCLibraryFunctions
5454
// CHECK-NEXT: unix.Vfork
5555
// CHECK-NEXT: unix.cstring.BadSizeArg
56+
// CHECK-NEXT: unix.cstring.NotNullTerminated
5657
// CHECK-NEXT: unix.cstring.NullArg
5758

5859
int main() {

clang/test/Analysis/bstring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang_analyze_cc1 -DUSE_BUILTINS -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
33
// RUN: %clang_analyze_cc1 -DVARIANT -analyzer-checker=core,unix.cstring,alpha.unix.cstring,unix.Malloc,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
44
// RUN: %clang_analyze_cc1 -DUSE_BUILTINS -DVARIANT -analyzer-checker=core,unix.cstring,alpha.unix.cstring,unix.Malloc,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
5-
// RUN: %clang_analyze_cc1 -DSUPPRESS_OUT_OF_BOUND -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring.BufferOverlap,alpha.unix.cstring.NotNullTerminated,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
5+
// RUN: %clang_analyze_cc1 -DSUPPRESS_OUT_OF_BOUND -analyzer-checker=core,unix.cstring,unix.Malloc,alpha.unix.cstring.BufferOverlap,unix.cstring.NotNullTerminated,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
66

77
#include "Inputs/system-header-simulator-cxx.h"
88
#include "Inputs/system-header-simulator-for-malloc.h"

0 commit comments

Comments
 (0)