Skip to content

Commit e973a55

Browse files
authored
Merge branch 'main' into llvmdll-lib-ADT
2 parents d988a28 + 94dc0a0 commit e973a55

File tree

245 files changed

+9302
-8352
lines changed

Some content is hidden

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

245 files changed

+9302
-8352
lines changed

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def find_compilation_database(path: str) -> str:
8787

8888

8989
def get_tidy_invocation(
90-
f: str,
90+
f: Optional[str],
9191
clang_tidy_binary: str,
9292
checks: str,
9393
tmpdir: Optional[str],
@@ -147,7 +147,8 @@ def get_tidy_invocation(
147147
start.append(f"--warnings-as-errors={warnings_as_errors}")
148148
if allow_no_checks:
149149
start.append("--allow-no-checks")
150-
start.append(f)
150+
if f:
151+
start.append(f)
151152
return start
152153

153154

@@ -490,7 +491,7 @@ async def main() -> None:
490491

491492
try:
492493
invocation = get_tidy_invocation(
493-
"",
494+
None,
494495
clang_tidy_binary,
495496
args.checks,
496497
None,

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Improvements to clang-tidy
103103
- Fixed bug in :program:`clang-tidy` by which `HeaderFilterRegex` did not take
104104
effect when passed via the `.clang-tidy` file.
105105

106+
- Fixed bug in :program:`run_clang_tidy.py` where the program would not
107+
correctly display the checks enabled by the top-level `.clang-tidy` file.
108+
106109
New checks
107110
^^^^^^^^^^
108111

clang/docs/ReleaseNotes.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ C Language Changes
150150
- Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which
151151
diagnoses implicit conversion from ``void *`` to another pointer type as
152152
being incompatible with C++. (#GH17792)
153+
- Added ``-Wc++-hidden-decl``, grouped under ``-Wc++-compat``, which diagnoses
154+
use of tag types which are visible in C but not visible in C++ due to scoping
155+
rules. e.g.,
156+
157+
.. code-block:: c
158+
159+
struct S {
160+
struct T {
161+
int x;
162+
} t;
163+
};
164+
struct T t; // Invalid C++, valid C, now diagnosed
165+
- Added ``-Wimplicit-int-enum-cast``, grouped under ``-Wc++-compat``, which
166+
diagnoses implicit conversion from integer types to an enumeration type in C,
167+
which is not compatible with C++. #GH37027
168+
- Split "implicit conversion from enum type to different enum type" diagnostic
169+
from ``-Wenum-conversion`` into its own diagnostic group,
170+
``-Wimplicit-enum-enum-cast``, which is grouped under both
171+
``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an
172+
int-to-enum conversion because the enumeration on the right-hand side is
173+
promoted to ``int`` before the assignment.
153174

154175
C2y Feature Support
155176
^^^^^^^^^^^^^^^^^^^
@@ -211,6 +232,8 @@ Non-comprehensive list of changes in this release
211232
- Added `__builtin_elementwise_exp10`.
212233
- For AMDPGU targets, added `__builtin_v_cvt_off_f32_i4` that maps to the `v_cvt_off_f32_i4` instruction.
213234
- Added `__builtin_elementwise_minnum` and `__builtin_elementwise_maxnum`.
235+
- No longer crashing on invalid Objective-C categories and extensions when
236+
dumping the AST as JSON. (#GH137320)
214237

215238
New Compiler Flags
216239
------------------
@@ -608,6 +631,8 @@ Arm and AArch64 Support
608631
- The ``+nosimd`` attribute is now fully supported for ARM. Previously, this had no effect when being used with
609632
ARM targets, however this will now disable NEON instructions being generated. The ``simd`` option is
610633
also now printed when the ``--print-supported-extensions`` option is used.
634+
- When a feature that depends on NEON (``simd``) is used, NEON is now automatically enabled.
635+
- When NEON is disabled (``+nosimd``), all features that depend on NEON will now be disabled.
611636

612637
- Support for __ptrauth type qualifier has been added.
613638

clang/include/clang/AST/DeclBase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,10 +2239,14 @@ class DeclContext {
22392239
return DC && this->getPrimaryContext() == DC->getPrimaryContext();
22402240
}
22412241

2242-
/// Determine whether this declaration context encloses the
2242+
/// Determine whether this declaration context semantically encloses the
22432243
/// declaration context DC.
22442244
bool Encloses(const DeclContext *DC) const;
22452245

2246+
/// Determine whether this declaration context lexically encloses the
2247+
/// declaration context DC.
2248+
bool LexicallyEncloses(const DeclContext *DC) const;
2249+
22462250
/// Find the nearest non-closure ancestor of this context,
22472251
/// i.e. the innermost semantic parent of this context which is not
22482252
/// a closure. A context may be its own non-closure ancestor.

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ def AnonEnumEnumConversion : DiagGroup<"anon-enum-enum-conversion",
103103
[DeprecatedAnonEnumEnumConversion]>;
104104
def EnumEnumConversion : DiagGroup<"enum-enum-conversion",
105105
[DeprecatedEnumEnumConversion]>;
106+
def ImplicitEnumEnumCast : DiagGroup<"implicit-enum-enum-cast">;
106107
def EnumFloatConversion : DiagGroup<"enum-float-conversion",
107108
[DeprecatedEnumFloatConversion]>;
108109
def EnumConversion : DiagGroup<"enum-conversion",
109110
[EnumEnumConversion,
111+
ImplicitEnumEnumCast,
110112
EnumFloatConversion,
111113
EnumCompareConditional]>;
112114
def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
@@ -154,10 +156,14 @@ def BuiltinRequiresHeader : DiagGroup<"builtin-requires-header">;
154156
def C99Compat : DiagGroup<"c99-compat">;
155157
def C23Compat : DiagGroup<"c23-compat">;
156158
def : DiagGroup<"c2x-compat", [C23Compat]>;
159+
def HiddenCppDecl : DiagGroup<"c++-hidden-decl">;
157160
def DefaultConstInitUnsafe : DiagGroup<"default-const-init-unsafe">;
158161
def DefaultConstInit : DiagGroup<"default-const-init", [DefaultConstInitUnsafe]>;
159162
def ImplicitVoidPtrCast : DiagGroup<"implicit-void-ptr-cast">;
160-
def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit]>;
163+
def ImplicitIntToEnumCast : DiagGroup<"implicit-int-enum-cast",
164+
[ImplicitEnumEnumCast]>;
165+
def CXXCompat: DiagGroup<"c++-compat", [ImplicitVoidPtrCast, DefaultConstInit,
166+
ImplicitIntToEnumCast, HiddenCppDecl]>;
161167

162168
def ExternCCompat : DiagGroup<"extern-c-compat">;
163169
def KeywordCompat : DiagGroup<"keyword-compat">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ def warn_unused_lambda_capture: Warning<"lambda capture %0 is not "
496496
"%select{used|required to be captured for this use}1">,
497497
InGroup<UnusedLambdaCapture>, DefaultIgnore;
498498

499+
def warn_decl_hidden_in_cpp : Warning<
500+
"%select{struct|union|enum}0 defined within a struct or union is not visible "
501+
"in C++">, InGroup<HiddenCppDecl>, DefaultIgnore;
502+
499503
def warn_reserved_extern_symbol: Warning<
500504
"identifier %0 is reserved because %select{"
501505
"<ERROR>|" // ReservedIdentifierStatus::NotReserved
@@ -4310,7 +4314,10 @@ def warn_impcast_string_literal_to_bool : Warning<
43104314
InGroup<StringConversion>, DefaultIgnore;
43114315
def warn_impcast_different_enum_types : Warning<
43124316
"implicit conversion from enumeration type %0 to different enumeration type "
4313-
"%1">, InGroup<EnumConversion>;
4317+
"%1">, InGroup<ImplicitEnumEnumCast>;
4318+
def warn_impcast_int_to_enum : Warning<
4319+
"implicit conversion from %0 to enumeration type %1 is invalid in C++">,
4320+
InGroup<ImplicitIntToEnumCast>, DefaultIgnore;
43144321
def warn_impcast_bool_to_null_pointer : Warning<
43154322
"initialization of pointer of type %0 to null from a constant boolean "
43164323
"expression">, InGroup<BoolConversion>;

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,7 @@ class Sema final : public SemaBase {
35233523
}
35243524

35253525
void warnOnReservedIdentifier(const NamedDecl *D);
3526+
void warnOnCTypeHiddenInCPlusPlus(const NamedDecl *D);
35263527

35273528
Decl *ActOnDeclarator(Scope *S, Declarator &D);
35283529

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const {
422422
OS << "IsActive: " << IsActive << "\n";
423423
OS << "InUnion: " << InUnion << "\n";
424424
OS << "IsFieldMutable: " << IsFieldMutable << "\n";
425+
OS << "IsArrayElement: " << IsArrayElement << "\n";
425426
OS << "Desc: ";
426427
if (Desc)
427428
Desc->dump(OS);

clang/lib/AST/ByteCode/Interp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ inline bool InitGlobalTempComp(InterpState &S, CodePtr OpPC,
15171517

15181518
template <PrimType Name, class T = typename PrimConv<Name>::T>
15191519
bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t I) {
1520-
if (S.checkingPotentialConstantExpression())
1520+
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
15211521
return false;
15221522
const Pointer &This = S.Current->getThis();
15231523
if (!CheckThis(S, OpPC, This))
@@ -1535,7 +1535,7 @@ template <PrimType Name, class T = typename PrimConv<Name>::T>
15351535
bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F,
15361536
uint32_t FieldOffset) {
15371537
assert(F->isBitField());
1538-
if (S.checkingPotentialConstantExpression())
1538+
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
15391539
return false;
15401540
const Pointer &This = S.Current->getThis();
15411541
if (!CheckThis(S, OpPC, This))
@@ -1602,7 +1602,7 @@ bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off);
16021602
bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off);
16031603

16041604
inline bool GetPtrThisField(InterpState &S, CodePtr OpPC, uint32_t Off) {
1605-
if (S.checkingPotentialConstantExpression())
1605+
if (S.checkingPotentialConstantExpression() && S.Current->getDepth() == 0)
16061606
return false;
16071607
const Pointer &This = S.Current->getThis();
16081608
if (!CheckThis(S, OpPC, This))

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,8 +1854,17 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
18541854

18551855
// Check for overlapping memory regions.
18561856
if (!Move && Pointer::pointToSameBlock(SrcPtr, DestPtr)) {
1857-
unsigned SrcIndex = SrcPtr.getIndex() * SrcPtr.elemSize();
1858-
unsigned DstIndex = DestPtr.getIndex() * DestPtr.elemSize();
1857+
// Remove base casts.
1858+
Pointer SrcP = SrcPtr;
1859+
while (SrcP.isBaseClass())
1860+
SrcP = SrcP.getBase();
1861+
1862+
Pointer DestP = DestPtr;
1863+
while (DestP.isBaseClass())
1864+
DestP = DestP.getBase();
1865+
1866+
unsigned SrcIndex = SrcP.expand().getIndex() * SrcP.elemSize();
1867+
unsigned DstIndex = DestP.expand().getIndex() * DestP.elemSize();
18591868
unsigned N = Size.getZExtValue();
18601869

18611870
if ((SrcIndex <= DstIndex && (SrcIndex + N) > DstIndex) ||
@@ -2189,6 +2198,50 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
21892198
return true;
21902199
}
21912200

2201+
static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
2202+
const CallExpr *Call) {
2203+
2204+
if (!S.inConstantContext())
2205+
return false;
2206+
2207+
const Pointer &Ptr = S.Stk.peek<Pointer>();
2208+
2209+
auto Error = [&](int Diag) {
2210+
bool CalledFromStd = false;
2211+
const auto *Callee = S.Current->getCallee();
2212+
if (Callee && Callee->isInStdNamespace()) {
2213+
const IdentifierInfo *Identifier = Callee->getIdentifier();
2214+
CalledFromStd = Identifier && Identifier->isStr("is_within_lifetime");
2215+
}
2216+
S.CCEDiag(CalledFromStd
2217+
? S.Current->Caller->getSource(S.Current->getRetPC())
2218+
: S.Current->getSource(OpPC),
2219+
diag::err_invalid_is_within_lifetime)
2220+
<< (CalledFromStd ? "std::is_within_lifetime"
2221+
: "__builtin_is_within_lifetime")
2222+
<< Diag;
2223+
return false;
2224+
};
2225+
2226+
if (Ptr.isZero())
2227+
return Error(0);
2228+
if (Ptr.isOnePastEnd())
2229+
return Error(1);
2230+
2231+
bool Result = true;
2232+
if (!Ptr.isActive()) {
2233+
Result = false;
2234+
} else {
2235+
if (!CheckLive(S, OpPC, Ptr, AK_Read))
2236+
return false;
2237+
if (!CheckMutable(S, OpPC, Ptr))
2238+
return false;
2239+
}
2240+
2241+
pushInteger(S, Result, Call->getType());
2242+
return true;
2243+
}
2244+
21922245
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
21932246
uint32_t BuiltinID) {
21942247
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2698,6 +2751,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
26982751
return false;
26992752
break;
27002753

2754+
case Builtin::BI__builtin_is_within_lifetime:
2755+
if (!interp__builtin_is_within_lifetime(S, OpPC, Call))
2756+
return false;
2757+
break;
2758+
27012759
default:
27022760
S.FFDiag(S.Current->getLocation(OpPC),
27032761
diag::note_invalid_subexpr_in_const_expr)

clang/lib/AST/DeclBase.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,18 @@ bool DeclContext::Encloses(const DeclContext *DC) const {
14221422
return getPrimaryContext()->Encloses(DC);
14231423

14241424
for (; DC; DC = DC->getParent())
1425-
if (!isa<LinkageSpecDecl>(DC) && !isa<ExportDecl>(DC) &&
1425+
if (!isa<LinkageSpecDecl, ExportDecl>(DC) &&
1426+
DC->getPrimaryContext() == this)
1427+
return true;
1428+
return false;
1429+
}
1430+
1431+
bool DeclContext::LexicallyEncloses(const DeclContext *DC) const {
1432+
if (getPrimaryContext() != this)
1433+
return getPrimaryContext()->LexicallyEncloses(DC);
1434+
1435+
for (; DC; DC = DC->getLexicalParent())
1436+
if (!isa<LinkageSpecDecl, ExportDecl>(DC) &&
14261437
DC->getPrimaryContext() == this)
14271438
return true;
14281439
return false;

clang/lib/AST/Mangle.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ void MangleContext::mangleObjCMethodName(const ObjCMethodDecl *MD,
367367
}
368368
OS << (MD->isInstanceMethod() ? '-' : '+') << '[';
369369
if (const auto *CID = MD->getCategory()) {
370-
OS << CID->getClassInterface()->getName();
371-
if (includeCategoryNamespace) {
372-
OS << '(' << *CID << ')';
370+
if (const auto *CI = CID->getClassInterface()) {
371+
OS << CI->getName();
372+
if (includeCategoryNamespace) {
373+
OS << '(' << *CID << ')';
374+
}
373375
}
374376
} else if (const auto *CD =
375377
dyn_cast<ObjCContainerDecl>(MD->getDeclContext())) {

clang/lib/Basic/Targets/AMDGPU.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
318318
Opts["__opencl_c_images"] = true;
319319
Opts["__opencl_c_3d_image_writes"] = true;
320320
Opts["cl_khr_3d_image_writes"] = true;
321+
322+
Opts["__opencl_c_generic_address_space"] =
323+
GPUKind >= llvm::AMDGPU::GK_GFX700;
321324
}
322325
}
323326

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ getCodeModel(const CodeGenOptions &CodeGenOpts) {
304304
.Case("kernel", llvm::CodeModel::Kernel)
305305
.Case("medium", llvm::CodeModel::Medium)
306306
.Case("large", llvm::CodeModel::Large)
307-
.Case("default", ~1u)
307+
.Cases("default", "", ~1u)
308308
.Default(~0u);
309309
assert(CodeModel != ~0u && "invalid code model!");
310310
if (CodeModel == ~1u)
@@ -617,7 +617,8 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
617617
return;
618618
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
619619
Options, RM, CM, OptLevel));
620-
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
620+
if (TM)
621+
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
621622
}
622623

623624
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,6 +3001,8 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
30013001
Ty = types::TY_CXX;
30023002
else if (CCCIsCPP() || CCGenDiagnostics)
30033003
Ty = types::TY_C;
3004+
else if (IsDXCMode())
3005+
Ty = types::TY_HLSL;
30043006
else
30053007
Ty = types::TY_Object;
30063008
}

0 commit comments

Comments
 (0)